﻿#pragma once
#include "Globalvf.h"
#include "lite_access.h"
class CENVEx;
class CSTMTEx;

class CDBCEx
{
public:
	CDBCEx( CENVEx *pEnv);     ///< 생성자.
	~CDBCEx();

public:
	CENVEx * m_pEnv;
	Lite_Dbc * m_pEngDbc;
	
	CSTMTEx * m_pStmt[STMT_COUNT];

public: // Variables.
    int m_nNatErr;			    /**< Native error code */
    char m_szSQLState[6];		/**< SQL state for SQLError() */
    SQLCHAR m_szLogMsg[1024];	/**< Message for SQLError() */
    char m_szDsn[50];			/**< ODBC data source name */
    char m_szDbName[50];		/**< SQLITE database name */
	int m_nXcelqrx;
	int m_nMagic;
	char m_szErr[128]; /**< SQLITE database name */

	long t0;			/**< Start time for SQLITE busy handler */
    int busyint;		/**< Interrupt busy handler from SQLCancel() */
    int *ov3;			/**< True for SQL_OV_ODBC3 */
    int ov3val;			/**< True for SQL_OV_ODBC3 */
    int m_nAutoCommit;		/**< Auto commit state */
    int m_nIntrans;		/**< True when transaction started */
    int nowchar;		/**< Don't try to use WCHAR */
    int dobigint;		/**< Force SQL_BIGINT for INTEGER columns */
    int shortnames;		/**< Always use short column names */
    int longnames;		/**< Don't shorten column names */
    int nocreat;		/**< Don't auto create database file */
    int fksupport;		/**< Foreign keys on or off */
    int curtype;		/**< Default cursor type */
    int step_enable;		/**< True for sqlite_compile/step/finalize */
    int trans_disable;		/**< True for no transaction support */
    int oemcp;			/**< True for Win32 OEM CP translation */
	int s3stmt_needmeta;	/**< True to get meta data in s3stmt_step(). */
public:
	char * m_pszSQLiteSQL;
public:
	void SetStatus(int nErr, char * pMsg, char * pState);
	BOOL Connect(char *pIP, int nPort, int nTimeout, int nRetry, char *pUID, char * pPWD); ///< 서버와 연결 함수.
	BOOL IsConnected(); ///< 연결 확인 함수.
	void Disconnect();  ///< 연결 종료 함수.
	CSTMTEx * CreateSTMT();  ///< STMT를 생성하는 함수.
	const char * GetErr();   ///< 에러를 리턴하는 함수.
	BOOL Exec(const char * pszSQL);   /// SQL문 수행.
	BOOL Begin(char** pErr);  ///< Begin수행 함수.
	BOOL Commit(char** pErr); ///< Commit 수행 함수.
	BOOL RollBack(char** pErr);  ///< RollBack 수행 함수.
	void SetState(int naterr, char *msg, char *st, ...); ///< 로그 함수.

	Lite_Stmt * CreateLiteSTMT();      ///< Lite_Stmt 객체를 만든다.
	void ResetStmt(CSTMTEx *pStmt);    ///< Stmt의 재사용을 위해서 사용 유무를 가린다.
	void DropStmt(CSTMTEx *pStmt);     ///< Stmt의 객체를 없앤다.
	void FreeSQLiteSQL();              ///< 메모리 해제.
};
